/**
 * Copyright (c) 2016-2019 人人开源 All rights reserved.
 * <p>
 * https://www.renren.io
 * <p>
 * 版权所有，侵权必究！
 */

package io.renren.modules.job.task;

import com.alibaba.fastjson.JSON;
import io.renren.modules.mqtt.MqttPushClient;
import io.renren.modules.mqtt.entity.MqttEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * mqtt心跳定时任务
 *
 * testTask为spring bean的名称
 *
 * @author Mark sunlightcs@gmail.com
 */
@Component("heartbeatTask")
public class HeartbeatTask implements ITask {

    @Autowired
    private MqttPushClient client;

    @Override
    public void run(String params) {
        MqttEvent heartbeatEvent = new MqttEvent();
        heartbeatEvent.setTopic(params);
        heartbeatEvent.setReplyMsgType("heartbeat");
        heartbeatEvent.setMsgType("heartbeat");
        heartbeatEvent.setTerminalNo("10000");
        heartbeatEvent.setAccessId("10001");
        heartbeatEvent.setSerialNo(String.valueOf(System.currentTimeMillis()));

        client.pushlish(params, JSON.toJSONString(heartbeatEvent));
    }
}
